home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Draw Editor / Source / DrawContent.cpp < prev    next >
Encoding:
Text File  |  1995-12-11  |  39.8 KB  |  1,413 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        DrawContent.cpp
  3.  
  4.     Contains:    Content Classes Implementation
  5.  
  6.     Written by:    Dave Stafford.
  7.     
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. // -- DrawEditor Includes --
  12.  
  13. #ifndef _DRAWCONTENT_
  14. #include "DrawContent.h"
  15. #endif
  16.  
  17. #ifndef _COMPILERDEFS_
  18. #include "CompDefs.h"
  19. #endif
  20.  
  21. #ifndef _DRAWEDTORUTILS_
  22. #include "DrawEditorUtils.h"
  23. #endif
  24.  
  25. #ifndef _DRAWEDITOR_
  26. #include "DrawEditor.h"
  27. #endif
  28.  
  29. #ifndef _SHAPECOMMANDS_
  30. #include "ShapeCommands.h"
  31. #endif
  32.  
  33. #ifndef _SHAPES_
  34. #include "Shapes.h"
  35. #endif
  36.  
  37. #ifndef _LINK_
  38. #include "Link.h"
  39. #endif
  40.  
  41. #ifndef _SELECTION_
  42. #include "Selection.h"
  43. #endif
  44.  
  45. // -- OpenDoc Includes --
  46.  
  47. #ifndef SOM_ODDraft_xh
  48. #include <Draft.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODShape_xh
  52. #include <Shape.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODFacet_xh
  56. #include <Facet.xh>
  57. #endif
  58.  
  59. #ifndef SOM_ODFrame_xh
  60. #include <Frame.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODStorageUnit_xh
  64. #include <StorageU.xh>
  65. #endif
  66.  
  67. #ifndef SOM_ODSession_xh
  68. #include <ODSessn.xh>
  69. #endif
  70.  
  71. #ifndef SOM_ODFrameFacetIterator_xh
  72. #include "FrFaItr.xh"
  73. #endif
  74.  
  75. // -- OpenDoc Utilities --
  76.  
  77. #ifndef _STDTYPIO_
  78. #include "StdTypIO.h"
  79. #endif
  80.  
  81. #ifndef _ODUTILS_
  82. #include "ODUtils.h"
  83. #endif
  84.  
  85. #ifndef _STORUTIL_
  86. #include <StorUtil.h>
  87. #endif
  88.  
  89. #ifndef _FOCUSLIB_
  90. #include "FocusLib.h"
  91. #endif
  92.  
  93. #ifndef _ORDCOLL_
  94. #include "OrdColl.h"
  95. #endif
  96.  
  97. #ifndef _ODMEMORY_
  98. #include "ODMemory.h"
  99. #endif
  100.  
  101. #ifndef _ODDEBUG_
  102. #include "ODDebug.h"
  103. #endif
  104.  
  105. // -- Toolbox Includes --
  106.  
  107. #ifndef mathRoutinesIncludes
  108. #include <math routines.h>
  109. #endif
  110.  
  111. #ifndef __MEMORY__
  112. #include <memory.h>
  113. #endif
  114.  
  115. #ifndef __DRAG__
  116. #include <Drag.h>
  117. #endif
  118.  
  119. //=============================================================================
  120. // CDrawContent
  121. //=============================================================================
  122.  
  123.  
  124. //-----------------------------------------------------------------------------
  125. // CDrawContent::CDrawContent
  126. //-----------------------------------------------------------------------------
  127.  
  128. CDrawContent::CDrawContent(DrawEditor* editor, COrderedList* shapes, COrderedList* pLinks, COrderedList* sLinks) 
  129. {
  130.     fDrawEditor = editor;
  131.  
  132.     fShapeList = shapes;
  133.     fPublishLinks =  pLinks;
  134.     fSubscribeLinks =  sLinks;
  135. }
  136.  
  137.  
  138. CDrawContent::CDrawContent(DrawEditor* editor)
  139. {
  140.     fDrawEditor = editor;
  141.     
  142.     fShapeList = kODNULL;
  143.     fPublishLinks = kODNULL;
  144.     fSubscribeLinks = kODNULL;
  145.     
  146. }
  147.  
  148. //-----------------------------------------------------------------------------
  149. // CDrawContent::~CDrawContent
  150. //-----------------------------------------------------------------------------
  151.  
  152. CDrawContent::~CDrawContent()
  153. {
  154. }
  155.  
  156.  
  157. //-----------------------------------------------------------------------------
  158. // CDrawContent::GetDrawEditor
  159. //-----------------------------------------------------------------------------
  160.  
  161. DrawEditor* CDrawContent::GetDrawEditor() const
  162. {
  163.     return fDrawEditor;
  164. }
  165.  
  166.  
  167. //-----------------------------------------------------------------------------
  168. // CDrawContent::GetShapeList
  169. //-----------------------------------------------------------------------------
  170.  
  171. COrderedList* CDrawContent::GetShapeList() const
  172. {
  173.     return fShapeList;
  174. }
  175.  
  176.  
  177. //-----------------------------------------------------------------------------
  178. // CDrawContent::RemoveShape
  179. //-----------------------------------------------------------------------------
  180.  
  181.  
  182.  
  183.  
  184. //-----------------------------------------------------------------------------
  185. //    CDrawContent::Externalize
  186. //-----------------------------------------------------------------------------
  187.  
  188. void CDrawContent::Externalize(Environment* ev, 
  189.                                     ODStorageUnit* storage, 
  190.                                     CCloneInfo* info)
  191. {
  192.     ODBoolean weBeganClone = kODFalse;
  193.     
  194.     // Externalize the content
  195.     TRY
  196.         ODDraft* dstDraft = storage->GetDraft(ev);
  197.         // If there is clone info then begin a clone
  198.         if (info && info->fKey==kODNULL)
  199.         {
  200.             info->fKey = info->fFromDraft->
  201.                 BeginClone(ev, dstDraft, info->fScopeFrame, info->fCloneKind);
  202.             weBeganClone = kODTrue;
  203.         }
  204.         
  205.         // Write the number of shapes
  206.         ODUShort count = fShapeList->Count();
  207.         
  208.         StorageUnitSetValue(storage, ev, sizeof(ODUShort), &count);
  209.                         
  210.     // Write the shapes Tag each one with it's 'externalization index'
  211.     ODUShort extInd = 0;
  212.     
  213.         COrdListIterator iter(fShapeList);
  214.         for ( CShape* shape = (CShape*)iter.First();
  215.              iter.IsNotComplete();
  216.              shape = (CShape*)iter.Next() )
  217.         {
  218.             // Write the shape type
  219.             ODSShort type = shape->GetShapeType();
  220.             StorageUnitSetValue(storage, ev, sizeof(ODSShort), &type);
  221.             
  222.             // Write the shape
  223.             shape->Write(ev, storage, info);
  224.         
  225.             // Tag shape with an index for use by links.
  226.             shape->SetExternalizationIndex(extInd++);
  227.         }
  228.         
  229.         this->ExternalizeLinks(ev, storage, info);
  230.     
  231.         if (weBeganClone)
  232.             info->fFromDraft->EndClone(ev, info->fKey);
  233.     
  234.     CATCH_ALL
  235.         // Abort clone operation
  236.         if (weBeganClone)
  237.             info->fFromDraft->AbortClone(ev, info->fKey);
  238.     
  239.         RERAISE;
  240.     ENDTRY
  241. }
  242.  
  243. //-----------------------------------------------------------------------------
  244. //    CDrawContent::ExternalizeSingleEmbeddedFrame
  245. //-----------------------------------------------------------------------------
  246.  
  247. void CDrawContent::ExternalizeSingleEmbeddedFrame(Environment* ev, 
  248.                                     ODStorageUnit* storage, 
  249.                                     CCloneInfo* info,
  250.                                     ODFrame* embeddedFrame)
  251. {    
  252.     // We should not be calling this method without valid clone info
  253.     THROW_IF_NULL(info);
  254.     
  255.     ODVolatile(info->fKey);
  256.     
  257.     TRY
  258.     
  259.         // Start a clone operation
  260.         if (info->fKey==kODNULL)
  261.             info->fKey = info->fFromDraft->BeginClone(ev, 
  262.                                                             storage->GetDraft(ev), 
  263.                                                             info->fScopeFrame, 
  264.                                                             info->fCloneKind);
  265.         
  266.         // Add the content frame property now, but don't clone the 
  267.         // frame until after the part is cloned
  268.         storage->AddProperty(ev, kODPropContentFrame);
  269.         storage->AddValue(ev, kODWeakStorageUnitRef);
  270.             
  271.         // Write a kODPropCloneKind so that any embedded shape which chooses
  272.         // to promise can record the cloneKind for use when fulfilling the promise.  Otherwise,
  273.         // a link update of a single embedded frame which promises in CloneInto, will fail
  274.         // when the promise is fulfilled due to using the wrong cloneKind.
  275.         
  276.         // This property/value must be provided so that an embedded frame which writes
  277.         // a promise within our clone block, can fulfill that promise using the same cloneKind
  278.         
  279.         storage->AddProperty(ev, kODPropCloneKindUsed);
  280.         storage->AddValue(ev, kODCloneKind);
  281.         StorageUnitSetValue(storage, ev, sizeof(ODCloneKind), &info->fCloneKind);
  282.         
  283.         // Clone the embedded part
  284.         ODPart* embeddedPart = embeddedFrame->AcquirePart(ev);
  285.         
  286.         info->fFromDraft->Clone(ev, 
  287.                                      info->fKey, 
  288.                                      embeddedPart->GetID(ev),
  289.                                      storage->GetID(ev), 
  290.                                      embeddedFrame->GetID(ev));
  291.         ODReleaseObject(ev, embeddedPart);
  292.         
  293.         // Clone the embedded frame to storage; must be done AFTER the part
  294.         // is cloned because the frame strongly references the part
  295.         ODID toFrameID = info->fFromDraft->Clone(ev, 
  296.                                                         info->fKey, 
  297.                                                         embeddedFrame->GetID(ev), 0,
  298.                                                         embeddedFrame->GetID(ev));
  299.                                                         
  300.         // Weakly reference the  frame so it must be explicitly cloned
  301.         // into the receiving draft
  302.         ODSUForceFocus(ev, storage, kODPropContentFrame, kODWeakStorageUnitRef);
  303.         ODStorageUnitRef aSURef; 
  304.         storage->GetWeakStorageUnitRef(ev, toFrameID, aSURef);
  305.         StorageUnitSetValue(storage, ev, sizeof(ODStorageUnitRef), aSURef);
  306.         
  307.         this->ExternalizeSingleFrameLinks(ev, storage, info);
  308.         
  309.         info->fFromDraft->EndClone(ev, info->fKey);
  310.         
  311.         CATCH_ALL
  312.             info->fFromDraft->AbortClone(ev, info->fKey);
  313.             RERAISE;
  314.             
  315.         ENDTRY
  316.         
  317.  
  318. }
  319.  
  320. //-----------------------------------------------------------------------------
  321. //    CDrawContent::Internalize
  322. //-----------------------------------------------------------------------------
  323.  
  324. void CDrawContent::Internalize(Environment* ev, 
  325.                                     ODStorageUnit* storageUnit, 
  326.                                     CCloneInfo* info)
  327. {
  328.  
  329.     ODDraft* dstDraft = fDrawEditor->GetDraft(ev);
  330.     
  331.     if (storageUnit->Exists(ev, kODPropContents, fDrawEditor->GetEditorKind(), 0))
  332.     {
  333.         CShape** shapeTable = kODNULL;
  334.         ODVolatile(shapeTable);
  335.         ODBoolean weBeganClone = kODFalse;
  336.         
  337.         TRY
  338.         
  339.             // Start a clone operation, if necessary
  340.             if (info && info->fKey==kODNULL)
  341.             {
  342.                 ODDraftKey key = info->fFromDraft->BeginClone(ev, dstDraft, info->fScopeFrame, info->fCloneKind);
  343.                 info->fKey = key;
  344.                 weBeganClone = kODTrue;
  345.             }
  346.             
  347.             // focus 
  348.             storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
  349.             
  350.             // Read the tag constant identifying this as a selection 
  351.             // as opposed to a complete document
  352.             ODSShort tag;
  353.             StorageUnitGetValue(storageUnit, ev, sizeof(ODSShort), &tag);
  354.             
  355.             // Read the document header data, if it exists
  356.             if (tag==kDrawDocument)
  357.             {
  358.                 // Here you would read document header data. That is, data that is would
  359.                 // normally be written out during an interchange operation, rather it is
  360.                 // only written out when the document is saved as a whole.
  361.             }
  362.             
  363.             // Read number of shapes
  364.             ODUShort count;
  365.             StorageUnitGetValue(storageUnit, ev, sizeof(ODUShort), &count);
  366.                 
  367.             shapeTable = new CShape*[count];
  368.             
  369.             // Temp storage for internalized shapes
  370.             COrderedList tCollection;
  371.             
  372.             //Then read in the new selection
  373.             for (ODUShort i = 0; i<count; i++)
  374.             {
  375.                 // Read the shape type
  376.                 ODSShort type;
  377.                 StorageUnitGetValue(storageUnit, ev, sizeof(ODSShort), &type);
  378.                 
  379.                 // Create a new shape
  380.                 CShape* shape = fDrawEditor->CreateShape(ev, type);
  381.                 if (shape != kODNULL)
  382.                 {
  383.                     // Read the shape
  384.                     shape->Read(ev, storageUnit, info);
  385.                     
  386.                     tCollection.AddFirst(shape);
  387.                     
  388.                 }
  389.                 shapeTable[i] = shape;
  390.             }
  391.     
  392.             // There are NEVER any links to be found when we transfer data from a link
  393.             // This test avoids executing all this code just to find out what is already 
  394.             // known.
  395.             
  396.             if (info->fCloneKind != kODCloneFromLink)  // testing for non-null link lists would also be valid
  397.             {
  398.                 // If this is the case of incorporating the content of a single embedded frame
  399.                 // then first deal with any subscribe link that was associated with the original
  400.                 // frame.  Then deal with any subscribe links associated with it's content
  401.                 // then deal with any publish link from the frame, then with any publish links
  402.                 // for the content.  We have to get all the subscribers before any publishers
  403.                 // because any shapes that are subscribed should end up pointing to the subscribe
  404.                 // link rather than to a publishers, so doing the subscribers first avoids a lot of 
  405.                 // cleanup code later.
  406.                 
  407.                 ODBoolean wasEmbedded = storageUnit->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0);
  408.                 ODULong contentFrameOffset = 0;
  409.                 
  410.                 if (wasEmbedded)
  411.                 {
  412.                     // we have to shift focus to kODPropContentFrame, need to know where to resume reading
  413.                     // kODPropContents when done. Could use an ODStorageUnitCursor if I knew how
  414.                     
  415.                     ODULong offset = storageUnit->GetOffset(ev);
  416.                         this->MergeSingleFrameSubLink(ev, storageUnit, info, &tCollection, contentFrameOffset);
  417.                     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
  418.                     storageUnit->SetOffset(ev, offset);
  419.                 }
  420.             
  421.                 this->InternalizeSubLinks(ev, storageUnit, info, shapeTable);
  422.             
  423.                 if (wasEmbedded)
  424.                 {
  425.                     ODULong offset = storageUnit->GetOffset(ev);
  426.                         this->MergeSingleFramePubLink(ev, storageUnit, info, &tCollection, contentFrameOffset);
  427.                     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);
  428.                     storageUnit->SetOffset(ev, offset);
  429.                 }
  430.                 
  431.                 this->InternalizePubLinks(ev, storageUnit, info, shapeTable);
  432.             }
  433.             
  434.             if (weBeganClone)
  435.             {
  436.                 info->fFromDraft->EndClone(ev, info->fKey);
  437.                 info->fKey = 0;
  438.             }
  439.             
  440.             // Can only add shapes to content after the clone has ended
  441.             // because GetFrame can only be called after a clone is complete.
  442.             // Since our shapes may be embedded content, we have to wait.
  443.             COrdListIterator iter(&tCollection);
  444.             for (CShape *shape = (CShape*)iter.First(); 
  445.                         iter.IsNotComplete(); 
  446.                         shape = (CShape*)iter.Next())
  447.             {
  448.                 this->AddShapeToPart(ev, shape);
  449.                 
  450.                 // Add it to content
  451.                 this->AddShape(ev, shape);
  452.             }
  453.             
  454.             this->PostCloneInternalizeLinks(ev, kODNULL);
  455.             
  456.         CATCH_ALL
  457.             if (weBeganClone)
  458.             {
  459.                 if (info->fKey != 0)
  460.                     info->fFromDraft->AbortClone(ev, info->fKey);
  461.             }
  462.                 
  463.             if (shapeTable)
  464.                 delete shapeTable;
  465.                 
  466.         ENDTRY
  467.     }
  468.     else
  469.     {
  470.         DebugStr("\pStorage unit should have a content property here.");
  471.     }
  472.     
  473. }
  474.  
  475. //-----------------------------------------------------------------------------
  476. //    CDrawContent::InternalizeSingleEmbeddedFrame
  477. //-----------------------------------------------------------------------------
  478.  
  479. void CDrawContent::InternalizeSingleEmbeddedFrame(Environment* ev, 
  480.                                     ODStorageUnit* storageUnit, 
  481.                                     CCloneInfo* info)
  482. {
  483.     ODDraft* toDraft = fDrawEditor->GetDraft(ev);
  484.     ODID newFrameID = 0;
  485.     ODID newPartID = 0;
  486.     ODPart* newPart = kODNULL;
  487.     Rect tShapeRect;
  488.     ODBoolean weBeganClone = kODFalse;
  489.     
  490.     TRY
  491.         // Gotta be cloning in this case
  492.         THROW_IF_NULL(info);
  493.         
  494.         // Start a clone operation, if necessary
  495.         if (info->fKey==kODNULL)
  496.         {
  497.             info->fKey = info->fFromDraft->BeginClone(ev, toDraft, info->fScopeFrame, info->fCloneKind);
  498.             weBeganClone = kODTrue;
  499.         }
  500.     
  501.         // Clone the part
  502.         ODID newPartID = info->fFromDraft->Clone(ev, info->fKey, storageUnit->GetID(ev), kODNULLID, kODNULLID);
  503.         
  504.         // If there is a content frame then use it
  505.         if (ODSUExistsThenFocus(ev, storageUnit, kODPropContentFrame, kODWeakStorageUnitRef))
  506.         {
  507.             // Clone the frame
  508.             ODStorageUnitRef aSURef;
  509.             StorageUnitGetValue(storageUnit, ev, sizeof(aSURef), aSURef);
  510.             
  511.             if (storageUnit->IsValidStorageUnitRef(ev, aSURef))
  512.             {
  513.                 ODID storageUnitID = storageUnit->GetIDFromStorageUnitRef(ev, aSURef);
  514.                 newFrameID = info->fFromDraft->Clone(ev, info->fKey, storageUnitID, 0, 0);
  515.             }
  516.             else
  517.                 THROW(kODErrInvalidStorageUnitRef);
  518.                 
  519.             this->InternalizeSingleEmbeddedFrameLinks(ev, storageUnit, info);
  520.                 
  521.         }
  522.         else
  523.         // otherwise, use the suggested frame shape
  524.         if (ODSUExistsThenFocus(ev, storageUnit, kODPropSuggestedFrameShape, kODNULL))
  525.         {
  526.             ODShape* tShape = info->fScopeFrame->CreateShape(ev);
  527.             tShape->ReadShape(ev, storageUnit);
  528.             ODRgnHandle tODRegion = tShape->GetQDRegion(ev);
  529.             tShapeRect = (*tODRegion)->rgnBBox;
  530.             
  531.             // Release acquired geometry
  532.             ODReleaseObject(ev, tShape);
  533.         }
  534.         else
  535.         {
  536.             DebugStr("\pStorage unit needs content frame of shape here.");
  537.         }
  538.             
  539.         // End the clone operation
  540.         if (weBeganClone)
  541.         {
  542.             info->fFromDraft->EndClone(ev, info->fKey);
  543.             info->fKey = 0;
  544.         }
  545.         
  546.         // Get the part 
  547.         newPart = toDraft->AcquirePart(ev, newPartID);
  548.         THROW_IF_NULL(newPart);
  549.  
  550.         // Create a shape.
  551.         CEmbeddingShape* tShape = (CEmbeddingShape*)(fDrawEditor->CreateShape(ev, kEmbeddingShape));
  552.         THROW_IF_NULL(tShape);
  553.  
  554.         // Size the shape if we read the suggested frame shape property
  555.         if (newFrameID==0)
  556.         {
  557.             tShape->SetBoundingBox(ev, tShapeRect);
  558.         }
  559.  
  560.         // Embed it
  561.         tShape->Embed(ev, newPart, info->fScopeFrame, newFrameID);
  562.  
  563.         // Add the shape to the part's content list
  564.         this->AddShapeToPart(ev, tShape);
  565.  
  566.         // Add the shape to this content object
  567.         this->AddShape(ev, tShape);
  568.         
  569.         this->PostCloneInternalizeLinks(ev, tShape);
  570.         
  571.         // Release acquired part
  572.         ODReleaseObject(ev, newPart);
  573.     
  574.     CATCH_ALL
  575.         // Something is amiss, abort the clone
  576.         if (weBeganClone && info->fKey!=0)
  577.             info->fFromDraft->AbortClone(ev, info->fKey);
  578.         
  579.         // Release acquired part
  580.         ODSafeReleaseObject(newPart);
  581.         
  582.         RERAISE;
  583.     ENDTRY
  584.             
  585. }
  586.  
  587. //-----------------------------------------------------------------------------
  588. //    CDrawContent::IsOneEmbeddedShape
  589. // This method returns the shape if there is only one embedded shape in
  590. // the selection, otherwise kODNULL is returned.
  591. //-----------------------------------------------------------------------------
  592.  
  593. CEmbeddingShape* CDrawContent::IsOneEmbeddedShape(Environment* ev) const
  594. {
  595.     // If there is only one shape and there is one embedding shape
  596.     // then return the shape, oltherwise return kODNULL
  597.     if (fShapeList->Count() ==1)
  598.     {
  599.         CShape* shape = (CShape *)fShapeList->First();
  600.         if (shape && (shape->GetShapeType() == kEmbeddingShape))
  601.             return (CEmbeddingShape*)shape;
  602.     }
  603.     
  604.     return kODNULL;
  605. }
  606.  
  607.  
  608. //-----------------------------------------------------------------------------
  609. //    CDrawContent::GetPublishLinks
  610. //-----------------------------------------------------------------------------
  611.  
  612. COrderedList* CDrawContent::GetPublishLinks() const
  613. {
  614.     return fPublishLinks;
  615. }
  616.  
  617.  
  618. //-----------------------------------------------------------------------------
  619. //    CDrawContent::GetSubscribeLinks
  620. //-----------------------------------------------------------------------------
  621.  
  622. COrderedList* CDrawContent::GetSubscribeLinks() const
  623. {
  624.     return fSubscribeLinks;
  625. }
  626.  
  627. //-----------------------------------------------------------------------------
  628. //    CDrawContent::HandleInternalizeContent
  629. //-----------------------------------------------------------------------------
  630.  
  631. void CDrawContent::HandleInternalizeContent(Environment* ev, 
  632.                                             ODStorageUnit* storage, 
  633.                                             CCloneInfo* info)
  634. {
  635.     // Is it a single embedded frame?
  636.     if (storage->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  637.     {
  638.         this->InternalizeSingleEmbeddedFrame(ev, storage, info);
  639.     }
  640.     else
  641.     // Is it our native kind?
  642.     if (storage->Exists(ev, kODPropContents, kDrawEditorKind, 0))
  643.     {
  644.         storage->Focus(ev, kODPropContents, kODPosUndefined, kDrawEditorKind, 0, kODPosFirstSib);
  645.         this->Internalize(ev, storage, info);
  646.     }
  647.     else
  648.     // We don't know what it is, try to embed
  649.     if (storage->Exists(ev, kODPropContents, kODNULL, 0))
  650.     {
  651.         storage->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosFirstSib);
  652.         this->InternalizeForeignContent(ev, storage, info);
  653.     }
  654.     
  655. }
  656.  
  657.  
  658. //-----------------------------------------------------------------------------
  659. //    CDrawContent::HandleTranslateContent
  660. //-----------------------------------------------------------------------------
  661.  
  662. void CDrawContent::HandleTranslateContent(Environment* ev, 
  663.                                             ODStorageUnit* storage, 
  664.                                             CCloneInfo* info,
  665.                                             ODBoolean doEmbed)
  666. {
  667.  
  668.     ODBoolean canMerge = storage->Exists(ev, kODPropContents, kDrawEditorKind, 0);
  669.  
  670.     // Is it a single embedded frame? 
  671.     if (storage->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  672.     {
  673.         // Merge if we're forcing a merge and content can be merged.
  674.         if (doEmbed || !canMerge)
  675.             this->InternalizeSingleEmbeddedFrame(ev, storage, info);
  676.         else
  677.             this->Internalize(ev, storage, info);
  678.     }
  679.     else
  680.     // Is it our native kind? And are we not forcing embed?
  681.     if (canMerge && !doEmbed)
  682.     {
  683.         storage->Focus(ev, kODPropContents, kODPosUndefined, kDrawEditorKind, 0, kODPosFirstSib);
  684.         
  685.         this->Internalize(ev, storage, info);
  686.     }
  687.     else
  688.     // We don't know what it is, or we are forcing embed = try to embed
  689.     if (storage->Exists(ev, kODPropContents, kODNULL, 0))
  690.     {
  691.         storage->Focus(ev, kODPropContents, kODPosUndefined, kODNULL, 0, kODPosFirstSib);
  692.         
  693.         this->InternalizeForeignContent(ev, storage, info);
  694.     }
  695.     
  696. }
  697.  
  698.  
  699. //-----------------------------------------------------------------------------
  700. //    CDrawContent::InternalizeForeignContent
  701. //-----------------------------------------------------------------------------
  702.  
  703. void  CDrawContent::InternalizeForeignContent(Environment* ev,  
  704.                                                 ODStorageUnit* contentSU,  
  705.                                                 CCloneInfo* info)
  706. {    
  707.     // Prepare to clone the item
  708.     ODDraft*    fromDraft = contentSU->GetDraft(ev);
  709.     ODDraft*    toDraft = fDrawEditor->GetDraft(ev);
  710.  
  711.     ODID        newPartID;
  712.     ODID        newFrameID = kODNULL;
  713.     ODShape*    newFrameShape = kODNULL;
  714.  
  715.     // These variables are used in a catch block, and so must be 
  716.     // declared volatile
  717.     ODVolatile(info);
  718.     ODVolatile(fromDraft);
  719.     
  720.     TRY
  721.         // Clone the root storage unit
  722.         info->fKey = fromDraft->BeginClone(ev, toDraft, info->fScopeFrame, info->fCloneKind);
  723.                 
  724.         newPartID = fromDraft->Clone(ev, info->fKey, contentSU->GetID(ev), 0, 0);
  725.     
  726.         // If a frame already exists for this part then clone it too.
  727.         if (contentSU->Exists(ev, kODPropContentFrame, kODWeakStorageUnitRef, 0))
  728.         {
  729.             ODStorageUnitRef aSURef;
  730.             contentSU->Focus(ev, kODPropContentFrame, kODPosSame, kODWeakStorageUnitRef, 0, kODPosUndefined);
  731.             StorageUnitGetValue(contentSU, ev, sizeof(ODStorageUnitRef), aSURef);
  732.             if ( contentSU->IsValidStorageUnitRef(ev, aSURef) )
  733.                 newFrameID = fromDraft->Clone(ev, info->fKey, contentSU->GetIDFromStorageUnitRef(ev, aSURef), 0, 0);                
  734.             else
  735.                 DebugStr("\p Invalid reference to content frame\n");
  736.         }
  737.         
  738.         fromDraft->EndClone(ev, info->fKey);
  739.     
  740.     CATCH_ALL
  741.         if (info->fKey!=0)
  742.             fromDraft->AbortClone(ev, info->fKey);
  743.     ENDTRY
  744.  
  745.     // Cloning is done, now embed the part
  746.     ODPart* newPart = toDraft->AcquirePart(ev, newPartID);
  747.     THROW_IF_NULL(newPart);
  748.     
  749.     // Create a content shape
  750.     CShape* newShape = fDrawEditor->CreateShape(ev, kEmbeddingShape);
  751.     
  752.     // We need a shape for the shape ( hee hee )
  753.     // If a frame was not provided then see if there is a suggested frame shape
  754.     if (newFrameID==kODNULL)
  755.     {
  756.         newFrameShape = info->fScopeFrame->CreateShape(ev);
  757.         THROW_IF_NULL(newFrameShape);
  758.     
  759.         if (contentSU->Exists(ev, kODPropSuggestedFrameShape, kODNULL, 0))
  760.         {
  761.             contentSU->Focus(ev, kODPropSuggestedFrameShape, kODPosUndefined, NULL, 1, kODPosUndefined);
  762.             newFrameShape->ReadShape(ev, contentSU);
  763.         }
  764.         else
  765.         {
  766.             // $$$$$ Need constant
  767.             ODRect tRect(ff(0), ff(0), ff(80), ff(80));
  768.             
  769.             newFrameShape->SetRectangle(ev, &tRect);
  770.         }
  771.  
  772.     
  773.         // Size the shape
  774.         newShape->SetBoundingBox(ev, newFrameShape);
  775.         
  776.         // Release acquired geometry
  777.         ODReleaseObject(ev, newFrameShape);
  778.     }
  779.     else
  780.     {
  781.         ODFrame* frame = toDraft->AcquireFrame(ev, newFrameID);
  782.         ODShape* frameShape = frame->AcquireFrameShape(ev, kODNULL);
  783.         
  784.         // Size the shape
  785.         newShape->SetBoundingBox(ev, frameShape);
  786.     }
  787.     
  788.     // Embed the part, CEmbeddingShape::Embed will release the part passed to it.
  789.     ((CEmbeddingShape*)newShape)->Embed(ev, newPart, info->fScopeFrame, newFrameID);
  790.     
  791.     // Release the newly created part
  792.     ODReleaseObject(ev, newPart);
  793.     
  794.     // Add the shape to the content list
  795.     this->AddShapeToPart(ev, newShape);
  796.     
  797.     // Add the shape to the selection
  798.     this->AddShape(ev, newShape);
  799. }
  800.  
  801.  
  802. #pragma segment Main
  803. void CDrawContent::AddPublishLink(CPublishLink* link)
  804. {
  805.     fPublishLinks->AddLast(link);
  806. }
  807.  
  808.  
  809. #pragma segment Main
  810. void CDrawContent::AddSubscribeLink(CSubscribeLink* link)
  811. {
  812.     fSubscribeLinks->AddLast(link);
  813. }
  814.  
  815.  
  816. #pragma segment Main
  817. void CDrawContent::RemoveSubscribeLink(CSubscribeLink* link)
  818. {
  819.     fSubscribeLinks->Remove(link);
  820. }
  821.  
  822.  
  823. #pragma segment Main
  824. void CDrawContent::RemovePublishLink(CPublishLink* link)
  825. {
  826.     fPublishLinks->Remove(link);
  827. }
  828.  
  829.  
  830. #pragma segment Main
  831. ODULong CDrawContent::Count()
  832. {
  833.     return fShapeList->Count();
  834. }
  835.  
  836.  
  837. #pragma segment Main
  838. void CDrawContent::ExternalizeLinks(Environment *ev,  ODStorageUnit *su,  CCloneInfo *info)
  839. {
  840.     // This test is for efficiency. If we skip the test, then for kODCloneToLink, OpenDoc will return an invalid
  841.     // ID for each link when we try to clone it, and ExternalizeLink will write out an invalid shape count (0), 
  842.     // which will indicate that no link is available when internalization takes place.
  843.     
  844.     if (!info || info->fCloneKind != kODCloneToLink)
  845.     {
  846.         // If this is not a publish link's content, then it should have been instantiated from a
  847.         // selection, and have at least empty link lists
  848.         
  849.         ASSERT_NOT_NULL(fSubscribeLinks);  
  850.         ASSERT_NOT_NULL(fPublishLinks);
  851.         
  852.         // Write out the subscribers first so that they can be internalized first
  853.         
  854.         ODUShort subCount = fSubscribeLinks->Count();
  855.         StorageUnitSetValue(su, ev, sizeof(ODUShort), &subCount);
  856.         
  857.         COrdListIterator sIter(fSubscribeLinks);
  858.         for (CSubscribeLink* sLink = (CSubscribeLink*)sIter.First(); sIter.IsNotComplete(); sLink = (CSubscribeLink*)sIter.Next())
  859.         {
  860.             sLink->ExternalizeLink(ev, su, info);
  861.         }
  862.         
  863.         // Write out the publishers last.
  864.         
  865.         ODUShort pubCount = fPublishLinks->Count();
  866.         StorageUnitSetValue(su, ev, sizeof(ODUShort), &pubCount);
  867.     
  868.         COrdListIterator pIter(fPublishLinks);
  869.         for (CPublishLink* pLink = (CPublishLink*)pIter.First(); pIter.IsNotComplete(); pLink = (CPublishLink*)pIter.Next())
  870.         {
  871.             pLink->ExternalizeLink(ev, su, info);
  872.         }
  873.         
  874.     }
  875.     else
  876.     {
  877.         ODUShort noLinks = 0;
  878.         StorageUnitSetValue(su, ev, sizeof(ODUShort), &noLinks);
  879.         StorageUnitSetValue(su, ev, sizeof(ODUShort), &noLinks);
  880.     }
  881.             
  882. }
  883.  
  884.  
  885. #pragma segment Main
  886. void CDrawContent::ExternalizeSingleFrameLinks(Environment *ev,  ODStorageUnit *su,  CCloneInfo *info)
  887. {
  888.     // give our one shape an externalization index
  889.     CShape *shape = (CShape *)fShapeList->First();
  890.     shape->SetExternalizationIndex(0);
  891.     
  892.     // If we're exporting a single embedded frame, that has is a link source and/or destination
  893.     // then the kODPropContents property belongs to the embedded part, which does not know about
  894.     // the links maintained by its container.  Use the kODPropProxyContents to write link data.
  895.  
  896.     // Focus to kODPropProxyContents and then call the ordinary ExternalizeLinks method.
  897.     ODSUForceFocus(ev, su, kODPropProxyContents, kDrawEditorKind);
  898.     
  899.     this->ExternalizeLinks(ev, su, info);
  900. }
  901.  
  902.  
  903. #pragma segment Main
  904. void CDrawContent::MergeSingleFrameSubLink( Environment *ev,  ODStorageUnit *su,  CCloneInfo *info, COrderedList* shapeList, ODULong& offset)
  905. {
  906.     if (su->Exists(ev, kODPropProxyContents, fDrawEditor->GetEditorKind(), 0))
  907.     {
  908.         su->Focus(ev, kODPropProxyContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);        
  909.         su->SetOffset(ev, offset);
  910.         
  911.         this->InternalizeSubLinks(ev, su, info, NULL);  // NULL = there's no shape table
  912.         
  913.         offset = su->GetOffset(ev);
  914.         
  915.         // There should only be one subscriber link written for what was a single embedded frame
  916.         CSubscribeLink *sLink = (CSubscribeLink *)fSubscribeLinks->First();
  917.     
  918.         if (sLink)
  919.         {
  920.             COrdListIterator iter(shapeList);
  921.             for (CShape* shape = (CShape*)iter.First(); iter.IsNotComplete(); shape = (CShape*)iter.Next())
  922.             {
  923.                 sLink->AddShape(ev,shape);
  924.             }
  925.         }
  926.     }
  927. }
  928.  
  929.  
  930. #pragma segment Main
  931. void CDrawContent::MergeSingleFramePubLink( Environment *ev,  ODStorageUnit *su,  CCloneInfo *info, COrderedList* shapeList, ODULong& offset)
  932. {    
  933.     if (su->Exists(ev, kODPropProxyContents, fDrawEditor->GetEditorKind(), 0))
  934.     {
  935.         su->Focus(ev, kODPropProxyContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);        
  936.         su->SetOffset(ev, offset);
  937.         
  938.         this->InternalizePubLinks(ev, su, info, NULL);  // NULL = there's no shape table
  939.         
  940.         offset = su->GetOffset(ev);
  941.         
  942.         // Normally, there is only one publisher for for what was a single embedded frame, BUT
  943.         // If content was removed from a link, or a containing frame with a link was merged
  944.         // into a single embedded frame withing that frame that had a link source, then we could
  945.         // have more than one source link.  Unfortuanately OpenDoc does not presently provide a way to 
  946.         // merge source links, so we may have many
  947.         
  948.         COrdListIterator iter(fPublishLinks);
  949.         for (CPublishLink *pLink = (CPublishLink *)iter.First(); iter.IsNotComplete(); pLink = (CPublishLink *)iter.Next())
  950.         {
  951.             COrdListIterator iter(shapeList);
  952.             for (CShape* shape = (CShape*)iter.First(); iter.IsNotComplete(); shape = (CShape*)iter.Next())
  953.             {
  954.                 pLink->AddShape(ev, shape);
  955.             }
  956.         }
  957.     }
  958. }
  959.  
  960.  
  961. #pragma segment Main
  962. void CDrawContent::InternalizeSubLinks( Environment *ev,  ODStorageUnit *su,  CCloneInfo *info, CShape** shapeTable)
  963. {
  964.     ODUShort subCount;
  965.     StorageUnitGetValue(su, ev, sizeof(ODUShort), &subCount);
  966.     
  967.     if (subCount == 0)
  968.         return;
  969.         
  970.     if (!fSubscribeLinks || !fPublishLinks)
  971.     {
  972.         DebugStr("\pwe seem to have found links in LinkUpdated");
  973.         return;
  974.     }
  975.         
  976.     CSubscribeLink* sLink = kODNULL;
  977.     
  978.     for (long j = 0; j < subCount; j++)
  979.     {
  980.         if (!sLink)
  981.             sLink = new CSubscribeLink(fDrawEditor->GetSelection());
  982.             
  983.         if (sLink->InternalizeLink(ev, su, info, shapeTable))
  984.         {
  985.             fSubscribeLinks->AddLast(sLink);
  986.             sLink = kODNULL;
  987.         }
  988.         
  989.     }
  990.     
  991.     if (sLink)
  992.         delete sLink;
  993.  
  994. }
  995.  
  996.  
  997. #pragma segment Main
  998. void CDrawContent::InternalizePubLinks( Environment *ev,  ODStorageUnit *su,  CCloneInfo *info, CShape** shapeTable)
  999. {
  1000.     ODUShort pubCount;
  1001.     StorageUnitGetValue(su, ev, sizeof(ODUShort), &pubCount);
  1002.     
  1003.     if (pubCount == 0)
  1004.         return;
  1005.         
  1006.     if (!fSubscribeLinks || !fPublishLinks)
  1007.     {
  1008.         DebugStr("\pwe seem to have found links in LinkUpdated");
  1009.         return;
  1010.     }
  1011.         
  1012.     CPublishLink* pLink = kODNULL;
  1013.     
  1014.     for (ODUShort j = 0; j < pubCount; j++)
  1015.     {
  1016.         if (!pLink)
  1017.             pLink = new CPublishLink(fDrawEditor->GetSelection());
  1018.             
  1019.         if (pLink->InternalizeLink(ev, su, info, shapeTable))
  1020.         {
  1021.             fPublishLinks->AddLast(pLink);
  1022.             pLink = kODNULL;
  1023.         }
  1024.         
  1025.     }
  1026.     
  1027.     if (pLink)
  1028.         delete pLink;
  1029.  
  1030. }
  1031.  
  1032.  
  1033. #pragma segment Main
  1034. void CDrawContent::InternalizeSingleEmbeddedFrameLinks(Environment* ev,  ODStorageUnit* su,  CCloneInfo* info)
  1035. {
  1036.     if (su->Exists(ev, kODPropProxyContents, fDrawEditor->GetEditorKind(), 0))
  1037.     {
  1038.         su->Focus(ev, kODPropProxyContents, kODPosUndefined, fDrawEditor->GetEditorKind(), 0, kODPosUndefined);        
  1039.         
  1040.         this->InternalizeSubLinks(ev, su, info, NULL);  // NULL = there's no shape table
  1041.         this->InternalizePubLinks(ev, su, info, NULL);  // NULL = there's no shape table
  1042.     }
  1043. }
  1044.  
  1045.  
  1046. #pragma segment Main
  1047. void  CDrawContent::PostCloneInternalizeLinks(Environment* ev, CShape* shape)
  1048. {
  1049.     ODDraft* toDraft = fDrawEditor->GetDraft(ev);
  1050.  
  1051.     COrderedList *scrapList = new COrderedList;
  1052.     CSubscribeLink *slink;
  1053.     CPublishLink *plink;
  1054.     
  1055.     // the only content object without these is CSubscribeLinkContent.  We should never have
  1056.     // any links to deal with internalizing here.
  1057.     if (!fSubscribeLinks || !fPublishLinks)
  1058.         return;
  1059.         
  1060.     COrdListIterator sLinkIte(fSubscribeLinks);
  1061.     for (slink = (CSubscribeLink *)sLinkIte.First(); sLinkIte.IsNotComplete(); slink = (CSubscribeLink *)sLinkIte.Next())
  1062.     {
  1063.         if (slink->PostCloneInternalizeLink(ev, toDraft, shape))
  1064.         {
  1065.             this->AddSubscriberToPart(ev, slink);
  1066.         }
  1067.         else
  1068.         {
  1069.             scrapList->AddLast(slink);
  1070.         }
  1071.             
  1072.     }
  1073.     
  1074.     while (scrapList->Count() != 0)
  1075.     {
  1076.         slink = (CSubscribeLink *)scrapList->RemoveFirst();
  1077.         fSubscribeLinks->Remove(slink);
  1078.         delete slink;
  1079.     }
  1080.  
  1081.     COrdListIterator pLinkIte(fPublishLinks);
  1082.     for (plink = (CPublishLink *)pLinkIte.First(); pLinkIte.IsNotComplete(); plink = (CPublishLink *)pLinkIte.Next())
  1083.     {
  1084.         if (plink->PostCloneInternalizeLink(ev, toDraft, shape))
  1085.         {
  1086.             this->AddPublisherToPart(ev, plink);
  1087.         }
  1088.         else
  1089.         {
  1090.             scrapList->AddLast(plink);
  1091.         }
  1092.         
  1093.     }
  1094.     
  1095.     while (scrapList->Count() != 0)
  1096.     {
  1097.         plink = (CPublishLink *)scrapList->RemoveFirst();
  1098.         fPublishLinks->Remove(plink);
  1099.         delete plink;
  1100.     }
  1101.     
  1102.     delete scrapList;
  1103. }
  1104.  
  1105. #pragma segment Main
  1106. void CDrawContent::AddPublisherToPart(Environment* ev, CPublishLink* pLink)
  1107. {
  1108.     pLink->AddToPart(ev);
  1109. }
  1110.  
  1111.  
  1112. #pragma segment Main
  1113. void CDrawContent::AddSubscriberToPart(Environment* ev, CSubscribeLink* sLink)
  1114. {
  1115.     sLink->AddToPart(ev);
  1116. }
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122. #pragma segment Main
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130. //=============================================================================
  1131. // CPartContent
  1132. //=============================================================================
  1133.  
  1134.  
  1135. //-----------------------------------------------------------------------------
  1136. // CPartContent::CPartContent
  1137. //-----------------------------------------------------------------------------
  1138.  
  1139. CPartContent::CPartContent(DrawEditor* editor, COrderedList* shapes, COrderedList* pLinks, COrderedList* sLinks) :
  1140. CDrawContent(editor, shapes, pLinks, sLinks)
  1141. {
  1142. }
  1143.  
  1144.  
  1145. //-----------------------------------------------------------------------------
  1146. //    CPartContent::~CPartContent
  1147. //-----------------------------------------------------------------------------
  1148.  
  1149. CPartContent::~CPartContent()
  1150. {
  1151. }
  1152.  
  1153.  
  1154. //-----------------------------------------------------------------------------
  1155. //    CPartContent::AddShapeToPart
  1156. //-----------------------------------------------------------------------------
  1157.  
  1158. void CPartContent::AddShapeToPart(Environment *ev, CShape* shape)//Override
  1159. {
  1160.     // The  CPartContent object IS the Part content, so this method does nothing.
  1161. }
  1162.  
  1163. //-----------------------------------------------------------------------------
  1164. //    CPartContent::Add
  1165. //-----------------------------------------------------------------------------
  1166. void CPartContent::Add(Environment* ev, CShape* shape)
  1167. {
  1168.     fDrawEditor->AddShape(ev, shape);
  1169. }
  1170.  
  1171. //-----------------------------------------------------------------------------
  1172. //    CPartContent::AddShape
  1173. //-----------------------------------------------------------------------------
  1174. void CPartContent::AddShape(Environment* ev, CShape* shape)
  1175. {
  1176.     fDrawEditor->AddShape(ev, shape);
  1177. }
  1178.  
  1179.  
  1180. //-----------------------------------------------------------------------------
  1181. //    CPartContent::Externalize
  1182. //-----------------------------------------------------------------------------
  1183.  
  1184. void CPartContent::Externalize(Environment* ev, 
  1185.                                     ODStorageUnit* storage, 
  1186.                                     CCloneInfo* info)
  1187. {
  1188.  
  1189.     // Externalize the part specific content first ( header )
  1190.     TRY
  1191.         // Write the tag constant identifying this as a selection 
  1192.         // as opposed to a complete document. That is, data that is
  1193.         // normally be written out during an interchange operation, rather it is
  1194.         // only written out when the document is saved as a whole.
  1195.         
  1196.         StorageUnitSetValue(storage, ev, sizeof(ODSShort), &kDrawDocument);
  1197.         
  1198.     CATCH_ALL
  1199.         ODSetSOMException(ev, ErrorCode());
  1200.     ENDTRY
  1201.  
  1202.     // Next, continue externalization of intrinsic content
  1203.     CDrawContent::Externalize(ev, storage, info);
  1204. }
  1205.  
  1206. #pragma segment Main
  1207. void CPartContent::AddPublisherToPart(Environment* ev, CPublishLink* pLink)//Override
  1208. {
  1209.     // This content object "is" the part content, so don't need to add it
  1210.     // Do need to do the other function that goes with being added to the part.
  1211.     
  1212.     pLink->SetSourcePart(ev);
  1213. }
  1214.  
  1215.  
  1216. #pragma segment Main
  1217. void CPartContent::AddSubscriberToPart(Environment* ev, CSubscribeLink* sLink)//Override
  1218. {
  1219.     // Since this content object is the part content, don't call AddToPart, and add the link again
  1220.     
  1221.     
  1222.     // Currently, an update precipitated during InitPartFromStorage will cause CSelection::CalcUpdateShape
  1223.     // to fail due to lack of a facet.
  1224.     
  1225.     // Defer this and do it in DisplayFrameConnected.
  1226.     // sLink->Register(ev);
  1227. }
  1228.  
  1229.  
  1230.  
  1231. //=============================================================================
  1232. // CPromiseContent
  1233. //=============================================================================
  1234.  
  1235.  
  1236. //-----------------------------------------------------------------------------
  1237. // CPromiseContent::CPromiseContent
  1238. // Initialize with same content as 'content'.
  1239. //-----------------------------------------------------------------------------
  1240.  
  1241. CPromiseContent::CPromiseContent(CDrawContent* content) :
  1242. CDrawContent(content->GetDrawEditor())
  1243. {
  1244.     fShapeList = new COrderedList(content->GetShapeList());
  1245.     fPublishLinks = new COrderedList(content->GetPublishLinks());
  1246.     fSubscribeLinks = new COrderedList(content->GetSubscribeLinks());
  1247. }
  1248.  
  1249.  
  1250. //-----------------------------------------------------------------------------
  1251. // CPromiseContent::CPromiseContent
  1252. //-----------------------------------------------------------------------------
  1253. CPromiseContent::CPromiseContent(DrawEditor* editor, COrderedList* shapeList):
  1254. CDrawContent(editor, shapeList, kODNULL, kODNULL)
  1255. {
  1256. }
  1257.  
  1258.  
  1259. //-----------------------------------------------------------------------------
  1260. // CPromiseContent::~CPromiseContent
  1261. //-----------------------------------------------------------------------------
  1262.  
  1263. CPromiseContent::~CPromiseContent()
  1264. {
  1265.     delete fShapeList;
  1266.     delete fPublishLinks;
  1267.     delete fSubscribeLinks;
  1268. }
  1269.  
  1270. //-----------------------------------------------------------------------------
  1271. //    CPromiseContent::Externalize
  1272. // Since we are only promising selections, externalize like a selection would
  1273. //-----------------------------------------------------------------------------
  1274. void CPromiseContent::Externalize(Environment* ev, 
  1275.                                     ODStorageUnit* storage, 
  1276.                                     CCloneInfo* info)
  1277. {
  1278.     // Externalize the selection specific content first ( header )
  1279.     TRY
  1280.         // Write the tag constant identifying this as a selection 
  1281.         // as opposed to a complete document
  1282.         StorageUnitSetValue(storage, ev, sizeof(ODSShort), &kDrawSelection);
  1283.     CATCH_ALL
  1284.         ODSetSOMException(ev, ErrorCode());
  1285.     ENDTRY
  1286.  
  1287.     // Next, continue externalization of intrinsic content
  1288.     CDrawContent::Externalize(ev, storage, info);
  1289. }
  1290.  
  1291.  
  1292. //-----------------------------------------------------------------------------
  1293. // CPromiseContent::AddShapeToPart
  1294. //-----------------------------------------------------------------------------
  1295.  
  1296. void CPromiseContent::AddShapeToPart(Environment *ev, CShape* shape)
  1297. {
  1298.     DebugStr("\pCPromiseContent can't AddShapeToPart");
  1299. }
  1300.  
  1301. //-----------------------------------------------------------------------------
  1302. //    CPromiseContent::AddShape
  1303. //-----------------------------------------------------------------------------
  1304. void  CPromiseContent::AddShape(Environment *ev, CShape* shape)
  1305. {
  1306.     DebugStr("\pCPromiseContent can't AddShape");
  1307. }
  1308.  
  1309. //-----------------------------------------------------------------------------
  1310. //    CSubscribeContent::Constructor
  1311. //-----------------------------------------------------------------------------
  1312. CSubscribeContent::CSubscribeContent(DrawEditor* editor, COrderedList* shapes, CSubscribeLink* subscribeLink) :
  1313. CDrawContent(editor, shapes, kODNULL, kODNULL)
  1314. {
  1315.     fSubscribeLink = subscribeLink;
  1316. }
  1317.  
  1318.  
  1319. //-----------------------------------------------------------------------------
  1320. //    CSubscribeContent::Destructor
  1321. //-----------------------------------------------------------------------------
  1322. CSubscribeContent::~CSubscribeContent()
  1323. {
  1324. }
  1325.  
  1326.  
  1327. //-----------------------------------------------------------------------------
  1328. //    CSubscribeContent::AddShapeToPart
  1329. //-----------------------------------------------------------------------------
  1330. void CSubscribeContent::AddShapeToPart(Environment *ev, CShape* shape)//Override
  1331. {
  1332.     fDrawEditor->AddShape(ev, shape);
  1333. }
  1334.  
  1335.  
  1336. //-----------------------------------------------------------------------------
  1337. //    CSubscribeContent::AddShape
  1338. //-----------------------------------------------------------------------------
  1339. void CSubscribeContent::AddShape(Environment *ev, CShape* shape)
  1340. {
  1341.     fSubscribeLink->AddShape(ev, shape);
  1342. }
  1343.  
  1344.  
  1345. //-----------------------------------------------------------------------------
  1346. //    CSelectionContent::Constructor
  1347. //-----------------------------------------------------------------------------
  1348. CSelectionContent::CSelectionContent(DrawEditor* editor, 
  1349.                                         COrderedList* shapes,
  1350.                                         COrderedList* pLinks,
  1351.                                         COrderedList* sLinks,
  1352.                                         CSelection* selection):
  1353. CDrawContent(editor, shapes, pLinks, sLinks)
  1354. {
  1355.     fSelection = selection;
  1356. }
  1357.  
  1358.  
  1359. //-----------------------------------------------------------------------------
  1360. //    CSelectionContent::Destructor
  1361. //-----------------------------------------------------------------------------
  1362. CSelectionContent::~CSelectionContent()
  1363. {
  1364. }
  1365.  
  1366. //-----------------------------------------------------------------------------
  1367. //    CSelectionContent::Externalize
  1368. //-----------------------------------------------------------------------------
  1369. void CSelectionContent::Externalize(Environment* ev, 
  1370.                                     ODStorageUnit* storage, 
  1371.                                     CCloneInfo* info)
  1372. {
  1373.     // Externalize the selection specific content first ( header )
  1374.     TRY
  1375.         // Write the tag constant identifying this as a selection 
  1376.         // as opposed to a complete document
  1377.         StorageUnitSetValue(storage, ev, sizeof(ODSShort), &kDrawSelection);
  1378.     CATCH_ALL
  1379.         ODSetSOMException(ev, ErrorCode());
  1380.     ENDTRY
  1381.  
  1382.     // Next, continue externalization of intrinsic content
  1383.     CDrawContent::Externalize(ev, storage, info);
  1384. }
  1385.  
  1386.  
  1387. //-----------------------------------------------------------------------------
  1388. //    CSelectionContent::AddShapeToPart
  1389. //-----------------------------------------------------------------------------
  1390. void CSelectionContent::AddShapeToPart(Environment *ev, CShape* shape)//Override
  1391. {
  1392.     fDrawEditor->AddShape(ev, shape);
  1393. }
  1394.  
  1395.  
  1396. //-----------------------------------------------------------------------------
  1397. //    CSelectionContent::AddShape
  1398. //-----------------------------------------------------------------------------
  1399. void CSelectionContent::AddShape(Environment *ev, CShape* shape)
  1400. {
  1401.     fSelection->AddToSelection(ev, shape, kODTrue);
  1402. }
  1403. #pragma segment Main
  1404. void CSelectionContent::AddSubscriberToPart(Environment* ev, CSubscribeLink* sLink)
  1405. {
  1406.     // Calling sLink->AddToPart may cause instantaneous update. That would close the selection
  1407.     // emptying the very list that is being iterated to make this call.
  1408.     
  1409.     // The paste or drop command object must make a copy of that list
  1410.     // for purposes of undo/redo, and must iterate the copied list calling sLink->AddToPart
  1411.     // after internalization is complete.
  1412. }
  1413.